package com.lifesea.notify.sms;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * <p>  </p>
 * User: chendw
 * Date: 2016/10/18 11:11
 */
public class SmsServiceRegister {

    private static final Logger logger = LoggerFactory.getLogger(SmsServiceRegister.class);

    /**
     * 短信发送渠道 key 号码前3位
     */
    public static final Map<String, Set<ISmsService>> senders = new HashMap<>();
    private static final String SPLIT_CHAR = ",";

    /**
     * 注册短信通道
     *
     * @param smsService
     */
    public static void register(String[] keys, ISmsService smsService) {
        logger.info("注册短信通道, keys:{}, sender:{}", keys, smsService);
        if (keys != null) {
            for (String key : keys) {
                Set set = SmsServiceRegister.senders.getOrDefault(key, new HashSet<>());
                set.add(smsService);

                SmsServiceRegister.senders.put(key, set);
            }
        }
    }

}
